﻿using System;
using System.Collections.Generic;
using System.Text;

using TTServer.Objects;

using libReadWrite;
using libCommonClass;

namespace TTServer.Messages
{
    public class SlideshowDataResponseMessage : TTMessage
    {
        private String _temporaryKey;

        public String TemporaryKey
        {
            get { return _temporaryKey; }
            set { _temporaryKey = value; }
        }

        private CSlideData[] _data;

        public CSlideData[] Data
        {
            get { return _data; }
            set { _data = value; }
        }

        public SlideshowDataResponseMessage(String temporaryKey, CSlideData[] data)
        {
            this.TemporaryKey = temporaryKey;
            this._data = data;
        }

        public SlideshowDataResponseMessage()
        {
            // TODO: Complete member initialization
        }

        public override void ReadMessage(BigEndianReader sr)
        {
            throw new NotImplementedException();
        }

        public override void WriteMessage(BigEndianWriter sw)
        {
            try
            {
                sw.Write((byte)MessageKind.SLIDESHOW_DATA_RESPONSE);
            }
            catch (Exception ex)
            {
                System.Console.WriteLine(ex.Message);
                throw ex;
            }
            sw.Write(Global.NO_LENGTH_CODE);

            sw.WriteString(this.TemporaryKey);

            sw.Write(_data.Length);

            for (int i = 0; i < _data.Length; i++)
            {
                if (_data[i] != null)
                {
                    sw.WriteString(_data[i].slideTitle);
                }
                else
                {
                    sw.WriteString("");
                }
            }
        }

        public override TTMessage Clone()
        {
            return new SlideshowDataResponseMessage();
        }

        public override int GetMessageID()
        {
            return MessageKind.SLIDESHOW_DATA_RESPONSE;
        }

        public override string GetMessageName()
        {
            return "SlideshowDataResponse";
        }
    }
}
